package jgl.vajra.management.part.mine.activity;

import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.HashMap;
import java.util.Map;

import jgl.vajra.management.R;
import jgl.vajra.management.bean.CarMemberBean;
import jgl.vajra.management.bean.MemberCenterBean;
import jgl.vajra.management.databinding.ActivityMemberCenterBinding;
import jgl.vajra.management.listener.MyToolbarViewListener;
import jgl.vajra.management.manager.AccountManager;
import jgl.vajra.management.manager.IntentManager;
import jgl.vajra.management.part.mine.contract.MemberCenterContract;
import jgl.vajra.management.part.mine.viewModel.MemberCenterViewModel;
import jgl.vajra.management.widget.databindingadapter.BaseBindingItemPresenter;
import jgl.vajra.management.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.management.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.management.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.management.widget.utils.UIUtils;

@CreateViewModel(MemberCenterViewModel.class)
public class MemberCenterActivity extends BaseMVVMActivity<MemberCenterViewModel, ActivityMemberCenterBinding> implements BaseBindingItemPresenter<MemberCenterBean.ContentBean>, MemberCenterContract.View {

    private SingleTypeBindingAdapter adapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_member_center;
    }

    @Override
    public void initView() {
        super.initView();

        mBinding.toolbar.setMyToolbarViewListener(new MyToolbarViewListener() {
            @Override
            public void onRightTextClick() {
                super.onRightTextClick();
                //会员规则
                IntentManager.toMemberRulesActivity(MemberCenterActivity.this);
            }
        });
        // 不可嵌套滑动
        mBinding.recyclerView.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.recyclerView.setFocusableInTouchMode(false);
        //设置布局管理器
        mBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new SingleTypeBindingAdapter(this, null, R.layout.item_member_center);
        mBinding.recyclerView.setAdapter(adapter);
        adapter.setItemPresenter(this);

        requestNetData();
    }

    private void requestNetData() {
        Map<String, Object> map = new HashMap<>();
        map.put("Authorization", AccountManager.getInstance().getLoginData(UIUtils.getContext()).authorization);
        mViewModel.getMemberCenterData(map);
    }

    //点击
    @Override
    public void onItemClick(int position, MemberCenterBean.ContentBean itemData) {

    }

    @Override
    public void returnMemberCenterData(MemberCenterBean data) {

        for (int i = data.contentData.size() - 1; i >= 0; i--) {
            if (data.contentData.get(i).type == 1) {
                data.contentData.remove(i);
            }
        }

        adapter.refresh(data.contentData);
    }
}
